package com.txl.web.servlets;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.txl.domain.ContactGroupBean;
import com.txl.service.ContactGroupService;
import com.txl.utils.WebUtils;

public class AddContactGroupServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ContactGroupService service = new ContactGroupService();
		List<ContactGroupBean> list = service.getAll();//获取2级分组
		request.setAttribute("list", list);
		request.getRequestDispatcher("/page/addgroup.jsp").forward(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ContactGroupBean cg = WebUtils.request2Bean(request, ContactGroupBean.class);
		ContactGroupService service = new ContactGroupService();
		try {
			service.addContactGroup(cg);
			System.out.println(cg.getGroupmemo());
		} catch (Exception e) {
			request.setAttribute("message", "添加失败！");
			request.getRequestDispatcher("/message.jsp").forward(request, response);
			return;
		}
		request.setAttribute("message", "添加成功！");
		request.getRequestDispatcher("/message.jsp").forward(request, response);
	}

}

